package com.cogent.dynamicform.facade.impl;

import java.util.HashMap;

import com.cogent.dao.facade.BussinessDaoFacade;
import com.cogent.dynamicform.domain.BusControlDomain;
import com.cogent.dynamicform.domain.FormDomain;
import com.cogent.dynamicform.expression.IBoolExpression;
import com.cogent.dynamicform.expression.IExpression;
import com.cogent.dynamicform.expression.impl.EqulHtBoolExpression;
import com.cogent.dynamicform.expression.impl.ExecuteSQLExpression;
import com.cogent.dynamicform.expression.impl.NotEqulHtBoolExpression;
import com.cogent.dynamicform.facade.IExpressionFacade;

public class ExpressionFacadeImpl implements IExpressionFacade {
	private static HashMap JUDGE_MAP = new HashMap();
	private static HashMap BUS_MAP = new HashMap();
	static {
		JUDGE_MAP.put("EQUALHT", new EqulHtBoolExpression());
		JUDGE_MAP.put("NOTEQULHT", new NotEqulHtBoolExpression());
	}
	
	static {
		BUS_MAP.put("EXECUTESQL", new ExecuteSQLExpression());
	}	
	
	public boolean doJudge(String expression, HashMap valMap) {
		String[] temps = expression.split("\\|");
		IBoolExpression iboolExpression = (IBoolExpression)JUDGE_MAP.get(temps[0]);
		return iboolExpression.doJudge(expression, valMap);
	}
	
	public boolean doExpression(BusControlDomain busControlDomain, BussinessDaoFacade bussinessFacade, FormDomain formDomain, HashMap valMap) {
		IExpression iexpression = (IExpression)BUS_MAP.get(busControlDomain.getType());
		return iexpression.doExpression(busControlDomain, bussinessFacade, formDomain, valMap);
	}

}
